<template>
  <div class="foregoer">
    <div class="foregoer_title">
      <p style="margin-right: 20px">{{ routerName }}</p>
    </div>
    <div class="foregoer_section">
      <div
        class="foregoer_section_book"
        @click="handleDetails(item.id)"
        v-for="(item, index) in teacherList"
        :key="index"
      >
        <img :src="item.img ? item.img : ''" alt="" />
        <p>{{ item.name }}</p>
      </div>
    </div>
    <div class="foregoer_pagination">
      <el-pagination
        @current-change="handleCurrentChange"
        :current-page.sync="teacherData.page"
        :page-size="teacherData.size"
        layout="total, prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getTeacherList } from "@/api/teacher";
export default {
  name: "foregoer",
  data() {
    return {
      total: 0,
      teacherData: {
        page: 1,
        size: 10,
        data: {
          type: "",
          keyword: "",
        },
      },
      teacherList: [],
      routerName: "",
    };
  },
  created() {
    this.routerName = this.$route.query.routerName;
  },
  mounted() {
    this.teacherData.data.keyword = this.$route.query.routerName;
    this.getTeacherList(this.teacherData);
  },
  methods: {
    getTeacherList(data) {
      getTeacherList(data).then((response) => {
        if (response.data.code === 20000) {
          const { list, totalRecords } = response.data.results;
          this.total = totalRecords;
          this.teacherList = list;
        }
      });
    },
    handleDetails(val) {
      this.$router.push({
        path: "/teacherTeam/foregoerDetails",
        query: {
          routerName: this.routerName,
          teacherId: val,
        },
      });
    },
    handleCurrentChange(val) {
      this.teacherData.page = val;
      this.getTeacherList(this.teacherData);
    },
  },
};
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.foregoer {
  .foregoer_title {
    height: 40px;
    background: #f1f1f1;
    text-align: right;
    line-height: 40px;
    font-weight: bold;
    font-size: 21px;
    color: #0a7b19;
  }
  .foregoer_section {
    display: flex;
    flex-wrap: wrap;
    margin-top: 20px;
    .foregoer_section_book {
      width: 120px;
      height: 160px;
      margin-right: 36px;
      margin-bottom: 46px;
      cursor: pointer;
      &:nth-child(7n) {
        margin: 0;
      }
      img {
        width: 100%;
        height: 100%;
      }
      p {
        width: 100%;
        height: 30px;
        line-height: 30px;
        font-weight: bold;
        text-align: center;
      }
    }
  }
  .foregoer_pagination {
    width: 900px;
    margin: 0 auto;
    display: flex;
    justify-content: center;
    margin-bottom: 80px;
    .foregoer_pagination_button {
      width: 86px;
      height: 38px;
      line-height: 38px;
      border: 1px solid #0a7b19;
      border-radius: 8px;
      color: #0a7b19;
      font-weight: bold;
      text-align: center;
      transition: all 0.2s linear;
      cursor: pointer;
      &:hover {
        background-color: #0a7b19;
        color: white;
      }
    }
  }
}
</style>
